/**
 * 
 */
package com.hexacta.hrs.repositories.impl;

import java.util.Collection;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;

import com.hexacta.hrs.domain.feedback.training.Training;
import com.hexacta.hrs.repositories.feedback.training.TrainingRepository;

/**
 * @author gvilla
 * 
 */
public class TrainingRecordObjectRepository extends HibernateRecordObjectRepository<Training> implements
        TrainingRepository {

    /**
     * @param entityClass
     */
    public TrainingRecordObjectRepository(final Class<Training> entityClass) {
        super(entityClass);
    }

    /*
     * (non-Javadoc)
     * 
     * @see
     * com.hexacta.hrs.repositories.RecordObjectRepository#matching(org.vectrics
     * .common.db.RecordObject)
     */
    @Override
    public Collection<Training> matching(final Training criteria) {
        Criteria crit = getSession().createCriteria(Training.class);

        if (criteria == null)
            return null;

        if (criteria.getDate() != null) {
            crit.add(Restrictions.eq("date", criteria.getDate()));
        }

        if (criteria.getName() != null) {
            crit.add(Restrictions.ilike("name", criteria.getName()));
        }

        return crit.list();
    }

    /*
     * (non-Javadoc)
     * 
     * @see
     * com.hexacta.hrs.repositories.feedback.training.TrainingRepository#getByName
     * (java.lang.String)
     */
    @Override
    public List<Training> getByName(final String trainingName) {
        Criteria crit = getSession().createCriteria(Training.class);

        crit.add(Restrictions.ilike("name", trainingName));

        return crit.list();
    }

}
